package top.frsf.starter.impl;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import top.frsf.enums.GameStateEnum;
import top.frsf.object.card.CardObject;
import top.frsf.object.card.PeaCard;
import top.frsf.object.card.RepeaterPeaCard;
import top.frsf.object.card.SnowPeaCard;
import top.frsf.panel.GamePanel;
import top.frsf.starter.Starter;

import java.awt.*;
import java.util.ArrayList;

import static top.frsf.constants.ImageConstant.Card.*;

/**
 * 卡片启动器
 *
 * @author FRSF
 * @since 2025/8/2 23:00
 */
@Data
@Slf4j
public class CardStarter implements Starter {
    /**
     * 豌豆射手卡片
     */
    private final PeaCard peaCard = new PeaCard();
    /**
     * 寒冰射手卡片
     */
    private final SnowPeaCard snowPeaCard = new SnowPeaCard();
    /**
     * 双发射手卡片
     */
    private final RepeaterPeaCard repeaterPeaCard = new RepeaterPeaCard();
    /**
     * 卡片列表
     */
    private final ArrayList<CardObject> cards = new ArrayList<>();
    /**
     * 卡片宽度
     */
    private final int cardWidth = 52;

    @Override
    public void init() {
        log.info("卡片启动器初始化");
        cards.add(peaCard);
        cards.add(snowPeaCard);
        cards.add(repeaterPeaCard);
        for (int i = 1; i < cards.size(); i++) {
            CardObject cardObject = cards.get(i);
            cardObject.setX(cardObject.getX() + cardWidth * i);
        }
    }

    @Override
    public void start(Graphics graphics) {
        if (GamePanel.state == GameStateEnum.RUNNING) {
            cards.forEach(card -> card.paintSelfImage(graphics));
        }
    }
}
